package org.budo.dubbo.protocol.http.aop.permission.app;

import java.lang.reflect.Method;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.budo.dubbo.protocol.http.util.BudoReflectionUtil;
import org.springframework.core.annotation.Order;

/**
 * @author limin
 */
@Order(1011)
public class AppPermissionCheckMethodInterceptor implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Method method = invocation.getMethod();
        AppPermissionCheck annotation = BudoReflectionUtil.getMethodAnnotation(method, AppPermissionCheck.class);

        if (null == annotation || !(annotation instanceof AppPermissionCheck)) {
            return invocation.proceed();
        }

//        Method interfaceMethod = BudoReflectionUtil.getInterfaceMethodCached(method);
//        String[] permissionNames = new String[] { interfaceMethod.getDeclaringClass().getSimpleName() + "." + interfaceMethod.getName() };
//
//        String appKey = "app-key-1";
//        Assert.notNull(appKey, "appKey in AppPermissionCheckMethodInterceptor can not be null");
//
//        for (String permissionName : permissionNames) {
//            if (null == permission) {
//                throw new AppPermissionCheckException(appKey, permissionName);
//            }
//        }

        // 权限检查通过
        return invocation.proceed();
    }
}